TR v1.9 - Texture Replacer for .NIF files.
------------------------------------------------------

I'm programmer and thus hate to write documentations; 
so let's try to make this short :)

TR is a tool to replace textures in one or several .NIF files.

The program has a more or less easy to use Windows-UI, but its
real power lies in the command-line: In the command-prompt,
TR can replace several textures in several files at once. 



---- Commandline Options ----------------------------------

Syntax: TR [options] filename [[?|*]texture(old) texture(new)]
        TR -v filename
        TR -#<num> filename texture(new)
        TR filename ** text

Optional switches:
 -v       = View all textures in this file and show those that would be changed
 -#<num>  = replace texture number <num>.
 -t#<num> = when old texture can be found more than once change only this one.
 -nb      = create no backup file
 -c       = case sensitive search
 -w       = wait for keypress after each action (ESC to continue without waiting)
 -u       = View/modify one file in UI-Mode
 -r       = Remove internal Textures from NIF  (Morrowind-only)
 -nr      = Don't repair texture names ('/' to '\'  Oblivion only)

Search operators:
  ?       = Replace all textures that contain this text
  *       = Replace this text in the texture-name with the new text
  **      = Place the new text in front of all texture-names


---- Description ------------------------------------------


- Parameter "-v" can be used now to highlight the textures that
  will be changed, when you remove the -v from the commandline.
  No chances in the .NIF will be done as long as the parameter -v is in.

- Parameter "-u" Displays the file in a crude DOS User-Interface (see below)

- Parameter "-r" is used to extract internal textures and thus
  make it possible to reskin that model. (see below)

- The tool makes a backup of the original file (xxxx.nif.bak).
  if you don't need a backup use the "-nb" switch to turn it off.

- While Morrowind accepts '/' and '\', Oblivion only accepts '\'.
  When you open an Oblivion-Model, TR automatically searches for '/'
  in all texture-names and replaces it with '\'. If you don't want this,
  for some reason, you can turn it off by using the parameter '-nr'.


- Normally TR.EXE ignores whether the texture names are in upper case or lower 
  case letters "Tx_imp_floor_01.dds" and "TX_IMP_FLOOR_01.DDS" are the same
  use "-c" if you want a case-sensitive search.

- Sometimes it's easier to use the parameter "-v" to see which textures 
  are used in the file, and then replace one texture by it's texture-number
  use "-#<num>" in this case, for example: "-#3" for the third texture used
  in the file or -#12 for the 12th.

- Finally it might be that a texture that is used more than once in a model
  if you want to replace only one of them you can use the parameter 
  "-t#<num>" In this case the number doesn't use the overall texture count 
  as used with parameter "-#<num>", but the count of textures that fit to 
  the search criteria (the ones that are shown highlighted with "-v")


As common in commandline programs, any parameters that contain a " "
need to be closed in quotation marks. ( "This is one file.nam" )

The NIF's filename supports the wildcards "?" (ignore one letter) 
and "*" (ignore several letters) as common in DOS commands, but there are
some exceptions: The filenames "name*.*" and "name*" will both be treated 
like "name*.nif". Also, "name.*" will be treated like "name.nif".
(And when you're really lazy: "*" is the same as "*.nif")


The name of the "old Texture" also supports wildcard-operators,
use them as the first letter of the "old texture":

"?"  to replace all textures that contain "texture(old)"

"*"  to replace only those parts of the texture-names 
     that contain the text you specified in "texture(old)"
     
"**" When "**" is given as "texture(old)" TR will put the 
     text in "texture(new) in front of all texture-names





---- TR.CFG ----------------------------------------------

TR supports a config-file "TR.CFG" which must be located
in the same directory as TR.EXE. Currently 3 entries are supported.
Just write them into the file, it's up to you whether you prefer 
to write them all in one line or want to use several lines:

-nb   Invert backup-logic. 
      Use this when you don't want TR to make backups by default.
      The commandline parameter "-nb" now activates the creation
      of backups instead of disabling it.

-nr   Don't repair texture-names in Oblivion files.
      Use this to keep TR from automatically replacing '/' with '\'
      when a Oblivion model is opened. The commandline-parameter
      "-nr" now activates texture-name repairing.

-c    Invert igcase-logic.
      Use this to make a case-sensitive search by default.
      The commandline-parameter "-c" can be used now to ignore 
      whether the texture names are in upper or lower case.

-u    Open the Windows User-interface by default instead of using 
      the console. Use this when you want the Windows-Menu although
      TR thinks it was started from the console.


You can also specify the default folder that opens when you browse
for textures in the Windows-GUI:

-t=e:\games\oblivion\data\textures


There are two config-entries that determine the starting position
and size of the windows-menu. Each of these entries needs to be in a
separate line, and the numbers always need to have 4 digits:

-p=xxxx/yyyy     (window's position) 

-s=xxxx/yyyy     (window's size)

e.g.:

-p=0250/0100

This will cause TR to open the window always 250 pixels left,
and 100 pixels below the top left corner of the screen.

-s=0400/0200

And this sets the window's width to 400 and the height to 200







---- User-Interface --------------------------------------

When you start TR.EXE in any way besides the console.
(e.g. assign it to be the program that opens .NIF-Files,
or double click on the exe in the explorer) then TR opens 
a windows-menu instead of giving just console-output.

In this mode you can modify only one .NIF.

Using the interface is simple:

- select a texture with the Up/Down keys or the mouse

- press "ENTER" or double-click on a texture to edit it.

- Type in a new texture-name and press "ENTER" to save it.

- Click on "X" to quit, "v" to save changes, 
  and "..." to browse for a texture

- press "ESC" or close the window to quit the program


Along with TR.EXE a console window is opened, in which you 
can read TR's output messages. If you don't like this window,
you can resize it and change it's position by right-clicking
on the top left corner and selecting Properties/Layout.

To change position and/or size of the GUI-window, you can
use the "-p" and "-s" entries in TR.CFG (see above)





---- Ripping internal Textures-----------------------------

(This function doesn't work with the NIF-version used by Oblivion)


The Parameter "-r" removes all internal textures from a model. 

The original model ("Name.nif") isn't touched by this function.
A new file "Name_ripped.nif" will be created. This new model will 
look for the external textures "Name_01.tga", "Name_02.tga" and so on.

The textures are extracted as ".RAW" files that can be loaded into Photoshop.
The settings vary, you need to try a bit: Header size is about 160 bytes;
Number of channels is usually 3 or 4 (the 4th channel is the alpha-channel);
(The alpha channel needs to be inverted after loading!)
Interleave-setting needs to be changed when the loaded pic looks checkered;
Height and wide are in powers of 2 (64/128/256) as usual. 
With a bit experience you can guess the right format from the file-size.

There are a lot of actions necessary to make the model work after 
removing the texture-entries. For those interested, and for debugging 
purposes, those actions are logged in "Name.LOG".


Here's an example with Lady E's palmtree:
(http://www.proudfootimaging.com/ladye/flora.shtml)

  PALMTREE.NIF          714.055

"TR palm* -r" will create the following files:

  PALMTREE_RIPPED.NIF    14.553    (The changed model)
  PALMTREE_01.RAW       349.695    (The old texture #1 in RAW format) 
  PALMTREE_02.RAW       262.314    (The old texture #2 in RAW format) 
  PALMTREE_03.RAW        87.539    (The old texture #3 in RAW format) 
  PALMTREE.LOG            2.611    (The logfile with detailed information)

The new model "PALMTREE_RIPPED.NIF" will require the textures 
"PALMTREE_01.TGA", "PALMTREE_02.TGA" and "PALMTREE_03.TGA".

The RAW files of this particular model need to be loaded in PS as follows:
                  
PALMTREE_01.RAW: 256 x 256 / 4 Channels / Interleaved / 8-Bit / Header: 173 
PALMTREE_02.RAW: 256 x 256 / 3 Channels / Interleaved / 8-Bit / Header: 171
PALMTREE_03.RAW: 128 x 128 / 4 channels / Interleaved / 8-Bit / Header: 159



Remarks: The command-line parameter "-r" overrides all other settings.
Also there is no support for multi-file-modification here. 
Wildcards work, but only the first fitting file will be worked on.

**********************************************************************
WARNING!!! Always save your plugin before viewing a ripped NIF for 
           the first time. When anything went wrong while removing 
           the textures and their references, TESCS will crash when 
           it tries to display the model in the Render/Preview window. 
**********************************************************************


---- Examples ---------------------------------------------

(let's take "In_impsmall_r_entr_01.nif" for the examples,
but I`ll rename it to 1.nif to make this better readable...)


TR 1.nif

 Let's see how the model looks before we change it:

 Filename: "1.nif"
 --------------------------------------------------
 Texture #01 at 000001EB = "Tx_imp_floor_01.tga"
 Texture #02 at 00000941 = "Tx_imp_ceiling_01.tga"
 Texture #03 at 00001099 = "Tx_imp_topside_01.tga"
 Texture #04 at 0000153B = "Tx_imp_topside_01.tga"
 Texture #05 at 000019DD = "Tx_imp_midside_01.tga"
 Texture #06 at 00001E7F = "Tx_imp_midside_01.tga"
 Texture #07 at 00002261 = "Tx_imp_stripmed_01.tga"
 Texture #08 at 00003094 = "Tx_imp_stripdark_01.tga"
 Texture #09 at 00004B28 = "Tx_imp_botside_01.tga"
 Texture #10 at 00004FCA = "Tx_imp_botside_01.tga"



TR -#3 1.nif ice01.tga

 replaces only texture #3:

 Filename: "1.nif"
 --------------------------------------------------
 Texture #01 at 000001EB = "Tx_imp_floor_01.tga"
 Texture #02 at 00000941 = "Tx_imp_ceiling_01.tga"
 Texture #03 at 00001099 = "ice01.tga"
 Texture #04 at 0000153B = "Tx_imp_topside_01.tga"
 Texture #05 at 000019DD = "Tx_imp_midside_01.tga"
 Texture #06 at 00001E7F = "Tx_imp_midside_01.tga"
 Texture #07 at 00002261 = "Tx_imp_stripmed_01.tga"
 Texture #08 at 00003094 = "Tx_imp_stripdark_01.tga"
 Texture #09 at 00004B28 = "Tx_imp_botside_01.tga"
 Texture #10 at 00004FCA = "Tx_imp_botside_01.tga"



TR 1.nif "Tx_imp_topside_01.tga" ice01.tga

 Will replace all textures with this name.

 Filename: "1.nif"
 --------------------------------------------------
 Texture #01 at 000001EB = "Tx_imp_floor_01.tga"
 Texture #02 at 00000941 = "Tx_imp_ceiling_01.tga"
 Texture #03 at 00001099 = "ice01.tga"
 Texture #04 at 0000153B = "ice01.tga"
 Texture #05 at 000019DD = "Tx_imp_midside_01.tga"
 Texture #06 at 00001E7F = "Tx_imp_midside_01.tga"
 Texture #07 at 00002261 = "Tx_imp_stripmed_01.tga"
 Texture #08 at 00003094 = "Tx_imp_stripdark_01.tga"
 Texture #09 at 00004B28 = "Tx_imp_botside_01.tga"
 Texture #10 at 00004FCA = "Tx_imp_botside_01.tga"



TR -t#2 1.nif "Tx_imp_topside_01.tga" ice01.tga

 Now only the second "Tx_imp_topside_01.tga" will be replaced.

 Filename: "1.nif"
 --------------------------------------------------
 Texture #01 at 000001EB = "Tx_imp_floor_01.tga"
 Texture #02 at 00000941 = "Tx_imp_ceiling_01.tga"
 Texture #03 at 00001099 = "Tx_imp_topside_01.tga"
 Texture #04 at 0000153B = "ice01.tga"
 Texture #05 at 000019DD = "Tx_imp_midside_01.tga"
 Texture #06 at 00001E7F = "Tx_imp_midside_01.tga"
 Texture #07 at 00002261 = "Tx_imp_stripmed_01.tga"
 Texture #08 at 00003094 = "Tx_imp_stripdark_01.tga"
 Texture #09 at 00004B28 = "Tx_imp_botside_01.tga"
 Texture #10 at 00004FCA = "Tx_imp_botside_01.tga"



TR 1.nif *side brick

 Will replace the text "side" with "brick" in all texture-names

 Filename: "1.nif"
 --------------------------------------------------
 Texture #01 at 000001EB = "Tx_imp_floor_01.tga"
 Texture #02 at 00000941 = "Tx_imp_ceiling_01.tga"
 Texture #03 at 00001099 = "Tx_imp_topbrick_01.tga"
 Texture #04 at 0000153B = "Tx_imp_topbrick_01.tga"
 Texture #05 at 000019DD = "Tx_imp_midbrick_01.tga"
 Texture #06 at 00001E7F = "Tx_imp_midbrick_01.tga"
 Texture #07 at 00002261 = "Tx_imp_stripmed_01.tga"
 Texture #08 at 00003094 = "Tx_imp_stripdark_01.tga"
 Texture #09 at 00004B28 = "Tx_imp_botbrick_01.tga"
 Texture #10 at 00004FCA = "Tx_imp_botbrick_01.tga"



TR 1.nif ?side my_nice_bricks.tga

 Will replace all textures that contain "side" in their names

 Filename: "1.nif"
 --------------------------------------------------
 Texture #01 at 000001EB = "Tx_imp_floor_01.tga"
 Texture #02 at 00000941 = "Tx_imp_ceiling_01.tga"
 Texture #03 at 00001099 = "my_nice_bricks.tga"
 Texture #04 at 0000153B = "my_nice_bricks.tga"
 Texture #05 at 000019DD = "my_nice_bricks.tga"
 Texture #06 at 00001E7F = "my_nice_bricks.tga"
 Texture #07 at 00002261 = "Tx_imp_stripmed_01.tga"
 Texture #08 at 00003094 = "Tx_imp_stripdark_01.tga"
 Texture #09 at 00004B28 = "my_nice_bricks.tga"
 Texture #10 at 00004FCA = "my_nice_bricks.tga"



TR 1.nif ?side -t#3 my_nice_bricks.tga

 Will only replace the 3rd texture that contains "side"

 Filename: "1.nif"
 --------------------------------------------------
 Texture #01 at 000001EB = "Tx_imp_floor_01.tga"
 Texture #02 at 00000941 = "Tx_imp_ceiling_01.tga"
 Texture #03 at 00001099 = "Tx_imp_topside_01.tga"
 Texture #04 at 0000153B = "Tx_imp_topside_01.tga"
 Texture #05 at 000019DD = "my_nice_bricks.tga"
 Texture #06 at 00001E7F = "Tx_imp_midside_01.tga"
 Texture #07 at 00002261 = "Tx_imp_stripmed_01.tga"
 Texture #08 at 00003094 = "Tx_imp_stripdark_01.tga"
 Texture #09 at 00004B28 = "Tx_imp_botside_01.tga"
 Texture #10 at 00004FCA = "Tx_imp_botside_01.tga"



TR 1.nif *side -t#3 brick

 And this will replace only the text in the 3rd texture that contains "side"

 Filename: "1.nif"
 --------------------------------------------------
 Texture #01 at 000001EB = "Tx_imp_floor_01.tga"
 Texture #02 at 00000941 = "Tx_imp_ceiling_01.tga"
 Texture #03 at 00001099 = "Tx_imp_topside_01.tga"
 Texture #04 at 0000153B = "Tx_imp_topside_01.tga"
 Texture #05 at 000019DD = "Tx_imp_midbrick_01.tga"
 Texture #06 at 00001E7F = "Tx_imp_midside_01.tga"
 Texture #07 at 00002261 = "Tx_imp_stripmed_01.tga"
 Texture #08 at 00003094 = "Tx_imp_stripdark_01.tga"
 Texture #09 at 00004B28 = "Tx_imp_botside_01.tga"
 Texture #10 at 00004FCA = "Tx_imp_botside_01.tga"



 TR 1.nif ** Textures\mymod\

 This will put the text "Textures\mymod\" in front of all texture names

 Filename: "1.nif"
 --------------------------------------------------
 Texture #01 at 000001EB = "Textures\mymod\Tx_imp_floor_01.tga"
 Texture #02 at 00000941 = "Textures\mymod\Tx_imp_ceiling_01.tga"
 Texture #03 at 00001099 = "Textures\mymod\Tx_imp_topside_01.tga"
 Texture #04 at 0000153B = "Textures\mymod\Tx_imp_topside_01.tga"
 Texture #05 at 000019DD = "Textures\mymod\Tx_imp_midside_01.tga"
 Texture #06 at 00001E7F = "Textures\mymod\Tx_imp_midside_01.tga"
 Texture #07 at 00002261 = "Textures\mymod\Tx_imp_stripmed_01.tga"
 Texture #08 at 00003094 = "Textures\mymod\Tx_imp_stripdark_01.tga"
 Texture #09 at 00004B28 = "Textures\mymod\Tx_imp_botside_01.tga"
 Texture #10 at 00004FCA = "Textures\mymod\Tx_imp_botside_01.tga"



Wildcards... (Finally TR.EXE shows it's true power)

Lets say, you want to reskin all imperial interiors. 
Make new textures with similar filenames as the one you want to replace
for example Tx_new_imp_floor_01.tga Tx_new_imp_ceiling_01.tga"

Then copy all imperial tiles ("In_impsmall*.nif") to your mod's directory.
and rename them (e.g. to "In_new_impsmall*.nif")


Finally open a DOS-Box in this folder, and use TR.EXE to completely 
reskin all files at once: 

  TR In_new_impsmall*.nif *Tx_imp Tx_new_imp

That's it, now all Models are reskinned...




---------------------------------------------------------

IMPORTANT:  

TES4 - OBLIVION:


TR was originally created for Morrowind's NIF files.
When used on a Morrowind-NIF, the programm takes the NIF-Structure
into account, and reliable finds all textures (and only those)

The new NIF-Format used by Oblivion has a new structure,
that is completely incompatible to the old approach. 

To make sure no random text is considered a texture, 
TR will only modify strings that begin with "texture\"
This applies to all original Oblivion-meshes, and all new models
should be placed in an own sub-folder of "Oblivion\textures\" anyway.

In addition, if the "new texture name" from the command-line 
doesn't begin with "texture\" this is corrected automatically.

 TR 1.nif -#1 ice01.dds

will be treated as

 TR 1.nif -#1 textures\ice01.dds



---- Contact/Credits --------------------------------------

Created by Jochen Gehring (aka JOG)

Email: jo.ge@gmx.net
Web: http://home.tiscali.de/jo.ge/ob


Thanks to the NIFLA-Team (http://games.groups.yahoo.com/group/NIFLA/)
and especially Taharez. Without their research on the NIF-format,
removing internal textures wouldn't have been possible.



---- Version History --------------------------------------

v0.9  (26.Mar.03)
      (Initial Release for CON3-Team)
 

v1.0  (30.May.03)

  - Added parameters "-v", "-#" and "-t#" 


v1.1  (01.Jun.03)

  - Completely rebuilt internal texture-name management. 

  - Program no longer does a brute-force search & replace,
    but cares about NIF-Header structures.

  - Added highlighting to parameter "-V"  

  - Added texture-name operators "?" and "*"
  

v1.2  (08.Oct.03) 
      (First public release)
 
  - Small fix: Filenames "name*.*" and "name*" will now be treated 
    like "name*.NIF". Also, "name.*" will be treated like "name.nif".
    This is to prevent TR.EXE from changing it's own backup files
    over and over again, filling the HD with new backups that have 
    an additional ".bak", until the filename is longer than 255 chars...


v1.3  (17.May.04)

  - Added texture-name operator "**" to add text before all texture names
    Useful to make models look for their textures in a subfolder. 


v1.4  (06.Jun.04)
 
  - When you provide at least a filename, TR will show the current textures 
    (like "-V") instead of displaying the help screen (e.g.: "TR mymodel.nif")

  - Fix: Parameter "-#<num>" no longer overwrites the old texture-name 
    with random junk when you forget to provide a new texture name.
    (instead the model's current textures will be shown...)



v1.5  (04.Aug.04)

  - TR now automatically clears the "read-only" flag on .NIFs
    (Useful when you work on files copied from CD...)  

  - Fix: case-sensitive search didn't work correctly.
  
  - Fix: changed texture-names were always in lower-case.

  - Added support for Config-File "TR.CFG"

  - Added crude User-Interface (Parameter "-u")   



v1.6  (09.Aug.04)

  - Internal textures are recognized now. Its no longer possible 
    to change them (and thus break the .NIF).

  - Added parameter "-r" to remove internal textures from the .NIF.  



v1.7  (31.Mar.06)

  - Added basic support for Oblivion's .NIFs



v1.7a (01.Apr.06)

  - Parameter -U now also works with Oblivion-files
  
  - Added parameter -w to wait for a keypress after each action



v1.8  (10.Apr.06)

  - TR is now a 32-bit program and runs on Win XP64

  - The program now behaves like any other Windows-Program when
    you don't start it from the command line. Finally the tool
    is also useful for users that don't know how to get along with
    the command-console. 

  - Limits on 20 textures in GUI-Mode and file-path limitation 
    on 128 chars were removed.


v1.8a (12.Apr.06)  
  
  - Windows-GUI:
    Added buttons for close/quit and file-selection to Edit-Texture-Window.
    Fixed some Graphical glitches.
   
  

v1.9  (16.Apr.06)

  - Windows-GUI:
    You can now specify a default-folder that TR opens when you browse
    for textures. (-t=<pathname> in TR.CFG)

  - When used on Oblivion-NIFs, TR now automatically searches for textures 
    that contain a slash ('/') and repairs them by replacing the '/' with '\'
    Added parameter "-nr" to turn this off.


